package com.ygxsk.carhome.ui.rice;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.RegexUtils;
import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.flyco.roundview.RoundTextView;
import com.gyf.immersionbar.ImmersionBar;
import com.jakewharton.rxbinding4.widget.RxTextView;
import com.jakewharton.rxbinding4.widget.TextViewAfterTextChangeEvent;
import com.kongzue.dialogx.dialogs.PopTip;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.trello.rxlifecycle4.android.ActivityEvent;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.alertview.AlertView;
import com.ygxsk.carhome.constant.ConstantApi;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.constant.ExtraValue;
import com.ygxsk.carhome.event.EventRiceTickMain;
import com.ygxsk.carhome.listener.DoSomeThingListener;
import com.ygxsk.carhome.listener.RxBus;
import com.ygxsk.carhome.response.CustomerPerson;
import com.ygxsk.carhome.response.EvaluateWadeInfo;
import com.ygxsk.carhome.retrofit.AddLogUpLoadInfo;
import com.ygxsk.carhome.retrofit.ApiException;
import com.ygxsk.carhome.retrofit.ApiRequestSubListener;
import com.ygxsk.carhome.retrofit.ApiService;
import com.ygxsk.carhome.retrofit.ErrorConsumer;
import com.ygxsk.carhome.retrofit.NetworkManager;
import com.ygxsk.carhome.retrofit.ResponseTransformer;
import com.ygxsk.carhome.rxbus.RxBusCarWade;
import com.ygxsk.carhome.ui.ErrorActivity;
import com.ygxsk.carhome.ui.evaluate.EvaluateWadePopu;
import com.ygxsk.carhome.utils.CommUtils;
import com.ygxsk.carhome.views.ClearEditText;
import com.ygxsk.integrated.retrofit.Parameterkey;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-07-26  15:28
 * @Description:饭票餐券的发放页面；分发页面
 */
public class RiceTicketPushActivity extends ErrorActivity {

    //搜索按钮 的idview
    @BindView(R.id.textviewriceticketsearch)
    RoundTextView textViewRiceTicketSearch;

    //选中人员之后的 人员回显；
//    @BindView(R.id.textviewinputphonechooserice)
//    TextView textViewInputPhoneChooseRice;

    //添加发送的按钮
    @BindView(R.id.layoutbuttonriceticketplay)
    RoundTextView layoutButtonRiceTicketPlay;

    @BindView(R.id.editviewinputcustomerphone)
    ClearEditText editViewInPutCustomerPhone;

    //餐券的页面的
    @BindView(R.id.textviewricetickforbidden)
    TextView textViewRicetickForbidden;

    //这里的弹窗是 客户的信息
    private ArrayList<EvaluateWadeInfo> mDataResources_customerPerson_for_popu = new ArrayList<>();

    //弹出是 搜索出来的这个客户的 列表
    private BasePopupView basePopupView_customerPerson;

    //选择的这个客户的id ,用在发送 优惠券上；
    private String customerId_upLoad;

    @OnClick({R.id.textviewriceticketsearch, R.id.layoutbuttonriceticketplay})//搜索按钮、发送餐券2按钮
    public void clickInRiceTicketMain(View view) {

        switch (view.getId()) {

            case R.id.textviewriceticketsearch: {//搜索按钮

                KeyboardUtils.hideSoftInput(RiceTicketPushActivity.this);

                method_SearchSomeThing(true);

                break;
            }

//            case R.id.constraintlayoutheadersmartgo: {//查看更多--也即是简单的历史记录，非核销记录
//
//                KeyboardUtils.hideSoftInput(RiceTicketPushActivity.this);
//
//                Bundle extra_bundle = new Bundle();
//                //携带是从哪个页面过去的？
//                //携带标志 是从 餐券发放过去的
//                extra_bundle.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE, ExtraValue.VALUE_JUMP_FORM_RICE_TICKET_OUT_ACTIVITY);
//
//                //2024-1-3 09:51:03 新增逻辑：从餐券过来和从客户关怀的优惠券过来的不同，要注意。
//                //是否是批量审核跳转携带值内容:该处是【否】，不是批量审核过来的
//                extra_bundle.putBoolean(ExtraKey.EXTRA_ISCHECKED_MORE_ITEMS_FLAG, false);
//
//                ActivityUtils.startActivity(extra_bundle, CardSumHistoryActivity.class);
//
//                break;
//            }

            case R.id.layoutbuttonriceticketplay: {//发放按钮--餐券的发送和提交

                KeyboardUtils.hideSoftInput(RiceTicketPushActivity.this);

                //校验用户的选中
                if (TextUtils.isEmpty(customerId_upLoad)) {
                    CommUtils.checkDialog(mAlertView);
                    mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_customer_person_upload), true);
                    mAlertView.show();
                    return;
                }

                CommUtils.checkDialog(mAlertView);
                mAlertView = new AlertView(StringUtils.getString(R.string.clearaddorsubmitsuretitletips), //提示
                        StringUtils.getString(R.string.alert_message_card_coupon),//提示内容:确定发送吗？
                        StringUtils.getString(R.string.clearcachecancel), //取消
                        new String[]{StringUtils.getString(R.string.clearaddorsubmitsure)},//确定
                        null, mActivityInstance, AlertView.Style.Alert, new com.ygxsk.carhome.alertview.OnItemClickListener() {//
                    @Override
                    public void onItemClick(Object o, int position) {

                        if (position != AlertView.CANCELPOSITION) {

                            method_gainAddSubmitInfo_upLoad();

                        }
                    }
                });

                mAlertView.setCancelable(true);
                mAlertView.show();

                break;
            }

            default:
                break;
        }

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mActivityInstance = this;

        if (mDataResources_customerPerson_for_popu == null) {
            mDataResources_customerPerson_for_popu = new ArrayList<>();
        }

        initViews();

        //暂时无提前数据加载
//        gainDatas();

    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();

        ImmersionBar.with(this)//
                .titleBar(R.id.toolbarygxskout)
                .fitsSystemWindows(true)//解决状态栏和布局重叠问题，任选其一，默认为false，当为true时一定要指定statusBarColor()，不然状态栏为透明色，还有一些重载方法
                //.statusBarColor(R.color.colorPrimary)//
                //.navigationBarColor(R.color.colorPrimary)//
                //.keyboardEnable(true)
                .init();
    }

    @Override
    protected int getContentViewId() {
//        return R.layout.activity_rice_ticket_out_activity;
        return R.layout.activity_rice_ticked_push;
    }

    @Override
    protected void initToolBar(ToolbarHelper toolbarHelper) {

        toolbarHelper.setTitle(getString(R.string.title_rice_card));
        toolbarHelper.setVersionName(true, AppUtils.getAppVersionName());
        toolbarHelper.setLayoutClose(false, "", null);

        toolbarHelper.setLayoutLeft(true, R.drawable.backicon, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //搜索客户信息，优先关闭软键盘
                KeyboardUtils.hideSoftInput(mActivityInstance);
                methodBack();
            }
        });

        toolbarHelper.setLayoutRight(false, 0, "", null);

        //右侧是【编辑】
//        toolbarHelper.setLayoutRight(true, 1, getString(R.string.title_cardverifi_right), new ClickUtils.OnDebouncingClickListener() {
//            @Override
//            public void onDebouncingClick(View v) {
//
//                //携带信息跳转到【编辑-提交】页面；
//                Bundle extra_bundle = new Bundle();
//
//                //携带是 餐券 到卡券核销 列表
//                extra_bundle.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE, ExtraValue.VALUE_JUMP_FORM_RICE_TICKET_OUT_ACTIVITY);
//
//                ActivityUtils.startActivity(extra_bundle, CardDistHistoryActivity.class);
//
//            }
//        });

    }

    @Override
    protected void onClickNodata(View v) {

        //

    }

    @Override
    protected void initViews() {

        mCompositeDisposable.add(RxBus.getInstance()
                .toObserverable(RxBusCarWade.class)//
                .subscribeOn(AndroidSchedulers.mainThread())//
                .observeOn(AndroidSchedulers.mainThread())//
                .subscribe(new Consumer<RxBusCarWade>() {

                    @Override
                    public void accept(RxBusCarWade rxBusCarWade) throws Throwable {

                        if (rxBusCarWade != null) {

                            if (rxBusCarWade.getActionFlag() == ExtraValue.MODIFY_EVALUATE_RICE_TICKET_PERSON_SELECT) {//【选择卡券发放的那个人】；

                                //搜索出这个被发放人员的
                                customerId_upLoad = rxBusCarWade.getEvaluateWadeInfo().getDictCode();

                                //提示用户选中的文本
//                                if (textViewInputPhoneChooseRice != null) {
//                                    textViewInputPhoneChooseRice.setText(rxBusCarWade.getEvaluateWadeInfo().getDictLabel());
//                                }

                                CommUtils.setTextTips_success(RiceTicketPushActivity.this, textViewRicetickForbidden, rxBusCarWade.getEvaluateWadeInfo().getDictLabel());

                            }
                        }
                    }
                }));

        //软键盘的搜索 按钮逻辑
        //软键盘的【搜索】
        if (editViewInPutCustomerPhone != null) {
            editViewInPutCustomerPhone.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {

                    if (actionId == EditorInfo.IME_ACTION_SEARCH || (keyEvent != null && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {

                        //关闭软键盘
                        KeyboardUtils.hideSoftInput(RiceTicketPushActivity.this);

                        method_SearchSomeThing(false);

                        return true;
                    }

                    return false;
                }
            });
        }

        //监听手机号的文本框：如果手机号文本框输入信息丢失，那么 textViewInputPhoneChoose 的文字 也改为原始文字：
        RxTextView.afterTextChangeEvents(editViewInPutCustomerPhone)
                .debounce(0, TimeUnit.MILLISECONDS)//
                .skip(1)//过滤到第一个空字符的内容,需要完整的手机号
                .subscribeOn(AndroidSchedulers.mainThread())//
                .observeOn(AndroidSchedulers.mainThread())//
                .subscribe(new Consumer<TextViewAfterTextChangeEvent>() {
                    @Override
                    public void accept(TextViewAfterTextChangeEvent textViewAfterTextChangeEvent) throws Throwable {

                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "过滤之后-监听到的内容是->" + textViewAfterTextChangeEvent.getView().getText().toString());

                        String inputValue = textViewAfterTextChangeEvent.getView().getText().toString();

                        if (!TextUtils.isEmpty(inputValue)) {

                            int length = inputValue.length();

                            if (length < ConstantApi.IS_PHONE_NUMBER_LENGTH) {

//                                KeyboardUtils.hideSoftInput(RiceTicketPushActivity.this);
                                CommUtils.setViewGone(textViewRicetickForbidden);


                            } else if (length == ConstantApi.IS_PHONE_NUMBER_LENGTH) {

                                method_SearchSomeThing(false);

                            }

                        }

//                            if (et_searchInCustom.isFocused()) {
//                                //LogUtils.d(ConstantApi.LOGCAT_NOMAL + "afterTextChangeEvents--处于获取焦点状态");
//                                et_searchInCustom.clearFocus();//如果处于占用焦点之中，那么清理焦点
//                            }

//                        if (TextUtils.isEmpty(textViewAfterTextChangeEvent.getView().getText().toString())) {
//                            if (textViewInputPhoneChoose != null) {
//                                textViewInputPhoneChoose.setText(getString(R.string.smartgo_des_search_full));
//                            }
//                        }


                    }
                }, new Consumer<Throwable>() {

                    @Override
                    public void accept(Throwable throwable) throws Throwable {
//                        function_apiException();
                    }
                });

    }

    @Override
    protected void gainDatas() {

        if (NetworkUtils.isConnected()) {

//            getServerDatasCardHistory();

        } else {

            ToastUtils.showShort(StringUtils.getString(R.string.http_exception_network));

        }

    }

    //通用的搜索逻辑
    private void method_SearchSomeThing(boolean isShowLoadDialog) {

        String inputPhoneNumber = editViewInPutCustomerPhone.getText().toString().trim();

        //手机号没有填写，是不能通过的
        if (TextUtils.isEmpty(inputPhoneNumber)) {//必须填充手机号的
            CommUtils.checkDialog(mAlertView);
            mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_customerphone_upload), true);
            mAlertView.show();
            return;
        }

        //校验用户输入的手机号
        if (!RegexUtils.isMobileSimple(inputPhoneNumber)) {
            //CommUtils.displayToastShort(LoginActivity.this, "电话格式不对");
            CommUtils.checkDialog(mAlertView);
            mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_customerphone_format), true);
            mAlertView.show();
            return;
        }

        if (!RegexUtils.isMobileExact(inputPhoneNumber)) {//精确验证手机号
            //CommUtils.displayToastShort(LoginActivity.this, "请输入有效手机号");
            CommUtils.checkDialog(mAlertView);
            mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_customerphone_effective), true);
            mAlertView.show();
            return;
        }

        if (mDataResources_customerPerson_for_popu != null && !mDataResources_customerPerson_for_popu.isEmpty()) {
            mDataResources_customerPerson_for_popu.clear();
        }

        gainCustomerByPhone(editViewInPutCustomerPhone.getText().toString().trim(), isShowLoadDialog);

    }

    //搜索客户的信息内容
    private void gainCustomerByPhone(String _userPhone, boolean isShowLoadDialog) {

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.phone, _userPhone);//,
//        map.put(Parameterkey.shopInfoId, mSession.getShopInfoId());//,
//        map.put(Parameterkey.customerId,_customerId);//填充搜索出来的这个客户的 唯一id
//        map.put(Parameterkey.pagination, pagination_upLoad);//传递的页码
//        map.put(Parameterkey.pageSize, Parameterkey.pageSize_default);//,搜索关键字

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.GETSHOPLATENTCUSTOMERLIST_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.getShopLatentCustomerList_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(true);//展示给用户的标志
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .getCustomerByPhone(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
                .compose(RiceTicketPushActivity.this.bindUntilEvent(ActivityEvent.DESTROY))//
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<ArrayList<CustomerPerson>>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

                        CommUtils.checkMaterialDialog(materialDialog);
                        CommUtils.setViewVisible(textViewRicetickForbidden);
                        CommUtils.myCustomMessageShow(mActivityInstance, textViewRicetickForbidden, serverMessage);


                        //这里仅仅给提示即可
//                        if (!TextUtils.isEmpty(serverMessage)) {
////                            ToastUtils.showShort(serverMessage);
//                            PopTip.show(serverMessage).iconWarning();
//                        } else {
//                            PopTip.show(getString(R.string.not_search_customer)).iconWarning();
//                        }

                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {

                        CommUtils.setViewGone(textViewRicetickForbidden);

                        //有进度圈圈的
                        if (isShowLoadDialog) {
                            //如果是自动搜索的，就不弹加载进度圈
                            //如果是点击【搜索】，就弹窗
                            method_create_materialDialog(mActivityInstance, ConstantSign.TIPS_LOADING);
                        }
                    }
                }).subscribe(new Consumer<ArrayList<CustomerPerson>>() {
                    @Override
                    public void accept(ArrayList<CustomerPerson> customerPersonArrayList) throws Throwable {

                        //如果搜索出来有数据，就隐藏软键盘
                        KeyboardUtils.hideSoftInput(RiceTicketPushActivity.this);

                        CommUtils.setViewGone(textViewRicetickForbidden);

                        //搜索完毕，即关闭进度圈
                        CommUtils.checkMaterialDialog(materialDialog);

                        if (customerPersonArrayList != null && !customerPersonArrayList.isEmpty()) {

                            for (CustomerPerson customerPerson : customerPersonArrayList) {

                                EvaluateWadeInfo evaluateWadeInfo = new EvaluateWadeInfo();
                                evaluateWadeInfo.setDictCode(customerPerson.getCustomerId());
                                evaluateWadeInfo.setDictLabel(customerPerson.getTrueName());
                                //特殊：添加手机号
                                evaluateWadeInfo.setUserPhoneNumber(customerPerson.getPhone());

                                if (mDataResources_customerPerson_for_popu != null) {
                                    mDataResources_customerPerson_for_popu.add(evaluateWadeInfo);
                                }

                            }

                            //-----------------------------------------------------------------------------------------------------------
                            //如果数据仅仅是只有一条，那么默认直接选中，减少一步用户操作：
                            if (mDataResources_customerPerson_for_popu != null && mDataResources_customerPerson_for_popu.size() == 1) {
                                mDataResources_customerPerson_for_popu.get(0).setChecked(true);
                            }
                            //-----------------------------------------------------------------------------------------------------------

                        } else {
                            //直接提示 搜索信息为空
                            PopTip.show(getString(R.string.not_search_customer)).iconWarning();
                        }

                        //-----------------------------------------------------------------------------------------------------------
                        if (mDataResources_customerPerson_for_popu != null && !mDataResources_customerPerson_for_popu.isEmpty()) {
                            method_showCustomerPersonDialog();
                        }
                        //-----------------------------------------------------------------------------------------------------------

                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {
                        function_apiException(apiException);
                    }
                });

    }

    //添加：弹出搜索出来的客户的列表，一般地是仅仅只有一条数据的；
    private void method_showCustomerPersonDialog() {

        EvaluateWadePopu evaluateWadePopu = new EvaluateWadePopu(RiceTicketPushActivity.this,//
                ExtraValue.MODIFY_EVALUATE_RICE_TICKET_PERSON_SELECT,//
                mDataResources_customerPerson_for_popu);

        evaluateWadePopu.setTitleName(getResources().getString(R.string.dialog_des_title));

        //搜索要弹窗的：客户信息
        basePopupView_customerPerson = new XPopup.Builder(RiceTicketPushActivity.this)
                .hasShadowBg(true)
                //.moveUpToKeyboard(false) //如果不加这个，评论弹窗会移动到软键盘上面;
                .isViewMode(true)
                //.autoDismiss(false)
                //.isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
                //.isThreeDrag(false) //是否开启三阶拖拽，如果设置enableDrag(false)则无效
                //.dismissOnTouchOutside(true)
                //.notDismissWhenTouchInView()
                .asCustom(evaluateWadePopu)//
                .show();

    }


    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (basePopupView_customerPerson != null) {
            basePopupView_customerPerson.onDestroy();
            basePopupView_customerPerson = null;
        }

        if (mDataResources_customerPerson_for_popu != null && !mDataResources_customerPerson_for_popu.isEmpty()) {
            mDataResources_customerPerson_for_popu.clear();
            mDataResources_customerPerson_for_popu = null;
        }


    }

    @Override
    protected void methodBack() {
        if (ActivityUtils.isActivityAlive(this)) {
            ActivityUtils.finishActivity(this);
        }
    }

    //执行上传发送这个优惠券的操作；
    private void method_gainAddSubmitInfo_upLoad() {

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.customerId, customerId_upLoad);//
        map.put(Parameterkey.shopInfoId, mSession.getShopInfoId());// "shopInfoId": 1495 //店铺ID

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_SENDCOUPONTOCUSTOMERRICETICK_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.sendCouponToCustomerRiceTick_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(true);//展示给用户的标志
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .sendCouponToCustomerRiceTick(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
                .compose(RiceTicketPushActivity.this.bindUntilEvent(ActivityEvent.DESTROY))
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<String>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);
                        CommUtils.checkMaterialDialog(materialDialog);
                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {
                        method_create_materialDialog(mActivityInstance, ConstantSign.TIPS_SUBMIT);
                    }
                }).subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String stringValue) throws Throwable {

                        //TipDialog.show(StringUtils.getString(R.string.add_submit_success), WaitDialog.TYPE.SUCCESS);
                        CommUtils.checkMaterialDialog(materialDialog);

                        methodSubmitSuccess(mActivityInstance, new DoSomeThingListener() {
                            @Override
                            public void doSomeThing() {

                                //通知列表刷新
                                EventRiceTickMain eventRiceTickMain = new EventRiceTickMain();
                                eventRiceTickMain.setMessage(ExtraValue.EVENTBUS_EVENT_TO_REFRESH_RICE_TICKED_MAIN_LIST);
                                EventBus.getDefault().post(eventRiceTickMain);

                                methodBack();

                            }
                        });

                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {
                        function_apiException(apiException);
                    }
                });

    }

}